#include "common.h"
PUBLIC S4B AddULLONG(PULLONG result,ULLONG u1,ULLONG u2)
{
  if((((U4B)0xFFFFFFFF)-((U4B)u1.low))>=u2.low) 
  {
     u1.low+=u2.low;
  }
  else
  {
    u1.high+=1; /*the low 32bit should minus 0xFFFFFFFF+1*/
    u1.low=((U4B)0xFFFFFFFF)-u1.low+1-u2.low;
  }
  if((((U4B)0xFFFFFFFF)-((U4B)u1.high))>=u2.high)
  {
     u1.high+=u2.high;
     *result=u1;
     return ARTIST_ERROR_OK;
  }
  return ARTIST_ERROR_UNKNOWN;
}

PUBLIC S4B CompareULLONG(ULLONG u1,ULLONG u2)
{
  if((u1.high>u2.high)||(u1.high==u2.high && u1.low>u2.low)) return 1;
  if(u1.low==u2.low && u1.high==u2.high) return 0;
  return 2;
}

PUBLIC S4B CompareULLONGU4B(ULLONG u1,U4B u2)
{
   ULLONG t;
   t.high=0;t.low=u2;
   return CompareULLONG(u1,t);
}


PUBLIC S4B SubductULLONG(PULLONG result,ULLONG u1,ULLONG u2)
{
  if(CompareULLONG(u1,u2)>=2) return 1;//Print("aaaaaaaaaaaaaaaaaaaaaaaaa");
  if(u1.low<u2.low)
  {
      u1.low=((U4B)0xFFFFFFFF-u2.low+1+u1.low);
      u1.high-=1;
  }  
 else
  {
      u1.low-=u2.low;
  }
  u1.high-=u2.high;
  *result=u1;
  return ARTIST_ERROR_OK;
}

PUBLIC S4B AddULLONGU4B(PULLONG result,ULLONG a1,U4B a2)
{
   ULLONG t;
   t.high=0;
   t.low=a2;
   AddULLONG(result,a1,t);
   return ARTIST_ERROR_OK;
}

PUBLIC S4B SubductULLONGU4B(PULLONG result,ULLONG s1,U4B s2)
{
   ULLONG t;
   t.high=0;
   t.low=s2;
   SubductULLONG(result,s1,t);
   return ARTIST_ERROR_OK;
}













